<?php
session_start();
require('../conn.php');
require('../functions.php');
require('admin.php');
$id = $_GET['aid'];
$row = $mysql->query("select * from `news` where id={$id}");
$news = $row[0];
$picsArr = explode(",", $news['img']);
if ($_POST) {
    $flag = $_POST['flag'];
    $code = $_POST['code'];
    $codearr = explode("&",$code);
    $codetype = $codearr[0];
    $codecontent = $codearr[1];
    $pic = implode(",", $_POST['pic']);
    $id = $_POST['id'];
    $content = $_POST['content'];
    $res = $mysql->execute("update `news` set `content` = '{$content}',`flag`={$flag},`img`='{$pic}',`code`={$codetype},`code_content`='{$codecontent}' WHERE `id`={$id}");
    if ($res) {
        echo "<script>alert('修改成功')</script>";
        echo "<script>location.href='./dynamic_detail.php?aid={$id}'</script>";
    }
}
//var_dump($picsArr);
?>
<?php include('head.php') ?>
<div class="container-fluid">
    <div class="row-fluid">
        <?php
        include('left.php'); ?>
        <div class="span9">
            <h1 class="page-title">动态详情</h1>

            <div class="well">
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="home">
                        <form id="tab" action="dynamic_detail.php" method="post">
                            <input name="id" value="<?= $news['id'] ?>" type="hidden">
                            <label>userId(用户Id)</label>
                            <input type="text" placeholder="用户Id" value="<?= $news['uid'] ?>" name="userid" readonly/>
                            <label>content(发表内容)</label>
                            <textarea rows="6" style="width: 500px" id="type" name="content"
                                      value=""><?= $news['content'] ?></textarea>

                            <div id="imgList">
                                <?php foreach ($picsArr as $pic):
                                    if ($pic != ""):
                                        if (strpos($pic, "ttp:")) {
                                            $pic1 = $pic;
                                        } else {
                                            $pic1 = "http://app.weiyouqu.net/" . $pic;
                                        }
                                        ?>
                                        <div class="img">
                                            <img src="<?= $pic1 ?>"/>
                                            <input type="text" name="pic[]" value="<?= $pic ?>"/>
                                        </div>
                                        <?php
                                    endif;
                                endforeach; ?>

                            </div>
                            <label>频道</label>
                            <select name="code">
                                <?php
                                $codetype = $mysql->query("select * from `codetype`");
                                foreach ($codetype as $item) {
                                    ?>
                                    <option value="<?= $item['code']."&".$item['content'] ?>"
                                    <?php
                                    if($item['code'] == $news['code'])
                                    echo "selected";
                                    ?>
                                    ><?= $item['title'] ?></option>
                                    <?php
                                }
                                ?>
                            </select>
                            <label>类型</label>
                            <select name="flag">
                                <option value="1"<?php if($news['flag']==1) echo "selected";?>>普通</option>
                                <option value="2"<?php if($news['flag']==2) echo "selected";?>>长图</option>
                                <option value="3"<?php if($news['flag']==3) echo "selected";?>>gif</option>
                                <option value="4"<?php if($news['flag']==4) echo "selected";?>>视频</option>
                            </select>
                            <label>pnum(点赞)</label>
                            <input type="text" value="<?= $news['pnum'] ?>" style="width:500px" name="psum" readonly>
                            <label>cnum(评论)</label>
                            <input type="text" value="<?= $news['cnum'] ?>" style="width:500px" name="cnum" readonly>
                            <label>snum(赠送)</label>
                            <input type="text" value="<?= $news['snum'] ?>" style="width:500px" name="snum" readonly>
                            <label>day(时间)</label>
                            <input type="text" value="<?= $news['day'] ?>" style="width:500px" name="day" readonly>
                            <label>top</label>
                            <input type="text" value="<?= $news['top'] ?>" style="width:500px" name="top" readonly><br>
                            <input type="submit" value="保存">
                        </form>
                    </div>
                </div>

            </div>

            <div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
                 aria-hidden="true">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h3 id="myModalLabel">Delete Confirmation</h3>
                </div>
                <div class="modal-body">

                    <p class="error-text"><i class="icon-warning-sign modal-icon"></i>Are you sure you want to delete
                        the user?</p>
                </div>
                <div class="modal-footer">
                    <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
                    <button class="btn btn-danger" data-dismiss="modal">Delete</button>
                </div>
            </div>
        </div>
    </div>
</div>

<footer>
    <hr>
    <p class="pull-right"><!--power by right--></p>

    <p><!--power by --></p>
</footer>


<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="lib/bootstrap/js/bootstrap.js"></script>


</body>
</html>